#include "loginwindow.h"
#include "browserapplication.h"
#include "../account/account.h"
#include "utils/logger.h"

#include <qstring.h>
#include <qmessagebox.h>

#include <iostream>

LoginWindow::LoginWindow(QWidget *parent)
    :QDialog(parent)
{
    setupUi(this);

    QObject::connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(loginOKClicked()));
    QObject::connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}

void LoginWindow::loginOKClicked()
{
    if ( (this->usernameComboBox->currentText().isEmpty())
            || (this->passwordLineEdit->text().isEmpty()) )
    {
        //QString title = "";
        //QString message = "";

        //std::cout<<this->usernameComboBox->currentText().toStdString();

        return;
    }
    BrowserApplication::instance()->doLogin(this->usernameComboBox->currentText().toStdString(), this->passwordLineEdit->text().toStdString());
    //emit loginClicked(this->usernameComboBox->currentText().toStdString(), this->passwordLineEdit->text().toStdString());


    // TODO
    // call AccountManager to create account

}
